package com.sgb.kjwl.view.widget;

import android.content.Context;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.transport.GoodsInfoTypeEntity3;
import com.sgb.kjwl.view.ui.adapter.transport.TransportLoadGoodsTimeAdapter3;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.adapter.TransportAdapterOnItemClick;

import java.util.ArrayList;
import java.util.List;

/**
 * Describe:
 * Author:  yangLei
 * Date:    2021/12/8
 */
public class LoadRadiusWindow extends BasePopWindow {

    private TransportLoadGoodsTimeAdapter3 radiusAdapter;

    private List<GoodsInfoTypeEntity3> loadRadius;

    private GoodsInfoTypeEntity3 currentItem;

    public LoadRadiusWindow(Context context) {
        super(context);
    }

    @Override
    protected int popLayout() {
        return R.layout.popwindow_goods_types;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        initRadiusData();
        RecyclerView recyclerView = holder.getPop().findViewById(R.id.type_list);

        //装货时间
        radiusAdapter = new TransportLoadGoodsTimeAdapter3(mContext, loadRadius);
        recyclerView.setLayoutManager(new GridLayoutManager(mContext, 4));
        recyclerView.setAdapter(radiusAdapter);
        radiusAdapter.setDefItem(1);
        radiusAdapter.setItemSelect(true);

        radiusAdapter.setOnItemClick(new TransportAdapterOnItemClick<GoodsInfoTypeEntity3>() {
            @Override
            public void onItemClick(GoodsInfoTypeEntity3 infoTypeEntity, int position) {
                if (onResultClick != null)
                    onResultClick.result(infoTypeEntity, position, null);
                currentItem = infoTypeEntity;
                dissMiss();
            }
        });
    }

    private void initRadiusData() {
        loadRadius = new ArrayList<>();
        loadRadius.add(new GoodsInfoTypeEntity3("0", "不限"));
        loadRadius.add(new GoodsInfoTypeEntity3("10", "10公里内"));
        loadRadius.add(new GoodsInfoTypeEntity3("50", "50公里内"));
        loadRadius.add(new GoodsInfoTypeEntity3("100", "100公里内"));
        loadRadius.add(new GoodsInfoTypeEntity3("150", "150公里内"));
        loadRadius.add(new GoodsInfoTypeEntity3("200", "200公里内"));
        loadRadius.add(new GoodsInfoTypeEntity3("250", "250公里内"));
        loadRadius.add(new GoodsInfoTypeEntity3("300", "300公里内"));
        loadRadius.add(new GoodsInfoTypeEntity3("500", "500公里内"));
    }


    public void setDefItem(int position) {
        radiusAdapter.setDefItem(position);
        if (loadRadius != null && loadRadius.size() > position)
            currentItem = loadRadius.get(position);
    }

    public boolean isSetRadius() {
        return currentItem != null;
    }

    public String getLoadRadiusStr() {
        return currentItem.getName();
    }

    public void resetSelectItem() {
        radiusAdapter.setDefItem(1);
        radiusAdapter.resetCheckDatas();
    }

}
